package cn.dansj.plugin;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;

public class ConditionalOnClassTransformer {
    public byte[] transform(byte[] originalBytes) {
        try {
            ClassReader cr = new ClassReader(originalBytes);
            ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
            ConditionalOnClassAnnotationVisitor cv = new ConditionalOnClassAnnotationVisitor(cw);
            // 跳过调试信息以加快处理速度
            cr.accept(cv, ClassReader.SKIP_DEBUG);
            if (cv.wasTransformed()) return cw.toByteArray();
        } catch (Exception e) {
            // Return original bytes if transformation fails
        }
        return originalBytes;
    }
}